<div id="car">
    <div class="title">
        <div>
            <span class="titleact">购车</span>
            <span class="titleact">管理</span>
        </div>
        <span>总共2件商品</span>
    </div>
    <div id="item-panel">
        <div class="mpanel car-item">
            <ul>
                <li>
                    <div class="mui-checkbox">
                        <input class="selectinpu" type="checkbox">
                    </div>
                </li>
                <li><img src="../../images/huajiao.jpg" /></li>
                <li>
                    <span class="car-item-title">汉源鲜花椒2斤 保鲜麻椒藤椒四川特产散装食用新鲜生花椒500g 2袋</span><br>
                    <span class="specification">重量：2kg</span>
                </li>
            </ul>
            <div class="car-item-total">
                <span class="total">￥<span class="price">39.6</span></span>
                <span class="itemact">
                    <input class="leave" type="button" value="-">
                    <input class="num" type="text" value="1">
                    <input class="add" type="button" value="+">
                </span>
            </div>
        </div>
        <div class="mpanel car-item">
            <ul>
                <li>
                    <div class="mui-checkbox">
                        <input class="selectinpu" type="checkbox">
                    </div>
                </li>
                <li><img src="../../images/muer.jpg" /></li>
                <li>
                    <span class="car-item-title">东北山黑木耳纯野生特级小碗耳500g包邮云秋木耳干货散装东北特产</span><br>
                    <span class="specification">重量：500g</span>
                </li>
            </ul>
            <div class="car-item-total">
                <span class="total">￥<span class="price">129</span></span>
                <span class="itemact">
                    <input class="leave" type="button" value="-">
                    <input class="num" type="text" value="1">
                    <input class="add" type="button" value="+">
                </span>
            </div>
        </div>
    </div>
    <div class="Carfooter">
        <div class="mui-input-row mui-checkbox mui-left">
            <label>全选</label>
            <input class="allChecked" type="checkbox">
        </div>
        <div class="payact">
            <span class="tosp">合计:<span class="cartotal">￥<span class="totalprice">0</span></span></span>
            <button type="button" class="mui-btn mui-btn-danger btnpay">结算</button>
        </div>
    </div>  
</div>
<script type="text/javascript">
    $("#item-panel").on("change",".selectinpu",function(){
        if(!this.checked){
            $(".allChecked").prop("checked",false);
        }
        total();
    });
    $("#item-panel").on("click",".add",function(){
        var num = $(this).prev();
        num.val(Number(num.val()) + 1);
        //console.log(num.val());
    });
    $("#item-panel").on("click",".leave",function(){
        var num = $(this).next();
        if(num.val() >1){
            num.val(Number(num.val()) - 1);
        }
    });
    $(".allChecked").change(function(){  
        if(this.checked){
            $(".selectinpu").each(function(){
                $(this).prop("checked",true);
            });
            total();
        }else{
            $(".selectinpu").each(function(){
                $(this).prop("checked",false);
            });
            total();
        }
    });
    
    function total(){
        var totalprice = 0;
        $(".selectinpu").each(function(){
            if(this.checked){
            var total = $(this).parents(".car-item").children(".car-item-total").children(".total").children(".price").text();
               totalprice = Number(totalprice) + Number(total);
            }
        });
        $(".totalprice").text(totalprice);
    }
</script>